<template>
	<view class="container">
		<view class="flex diygw-autoview diygw-col-24 flex-direction-column autoview-clz">
			<!-- #ifdef MP-WEIXIN -->
			<view class="diygw-absolute autoview_0">
				<view class="flex diygw-col-18 search-clz">
					<view class="diygw-search">
						<view class="flex1 align-center flex padding-xs solid radius">
							<text class="diy-icon-search" style="color: "></text>
							<input class="flex1" name="search" type="" v-model="name" placeholder="请输入" />
						</view>
						<view @click="searchByName" style="color: #333 !important"
							class="diygw-tag margin-left-xs radius-xs"> 搜索 </view>
					</view>
				</view>
			</view>
			<view class="search-filter" @tap="orderbyChange" :class="{'text-theme': hasChoose}">
				<image class="search-filter-image" src="https://www.dtxtkj.com/app/images/filter.png"></image>
			</view>
			<fjj-condition ref='condition' @touchmove.stop :color="color" :list="filterData"
				:defaultValue="defaultValue" @result="resultConditon" />
			<!--  #endif -->
		</view>

		<!-- 列表 -->
		<view class="data-list">
			<view  v-for="(item, rowIndex) in datalist" :key="rowIndex">
				<view class="data-item" @click="goToDetail(item)">
					<view class="data-info">
						<text class="data-name">
							<text>{{ '智店星-'+item.name }}</text>
						</text>
						<text class="data-info-detail">门店地址: {{ item.region + ' ' +  item.address}}</text>
						<text v-if="item.phone" class="data-info-detail">联系电话: {{ item.phone }}</text>
					</view>
				</view>
				<view class="data-item-btn">
					<button class="btn delete" @click="deleteObj(item)">删除</button>
					<button class="btn view" @click="goToDetail(item)">编辑</button>
				</view>
			</view>
		</view>
	
		<!-- 悬浮加号按钮 -->
		<view class="float-button" @click="handleFloatButtonClick">
			<image class="plus-icon" src="/static/add.png"></image>
		</view>
		
	</view>
</template>

<script>
	import fjjCondition from '@/components/fjj-condition/fjj-condition.vue';
	import filterData from '@/common/data/cash/pettyCash_filter.js';
	import dataDictionary from '@/common/data/dataDictionary.js';
	export default {
		data() {
			return {
				color: '#4D7BFE',
				hasChoose: false,
				defaultValue: {},
				filterData: filterData,
				datalist: [],
				feildOpt: dataDictionary.employee,
				sourceOpt: {},
				typeOpt: {},
				name: '',
				searchParam: {
					name: '',
					storeId: '',
					roleId: '',
					status: '',
				}
			};
		},
		components: {
			fjjCondition,
		},
		computed: {

		},
		onLoad() {
			// 初始化过滤值
			this.initFilterData();
			//搜索
			this.onSearch();
		},

		onShow() {
			this.onSearch();
		},

		methods: {
			async initFilterData() {
				if (this.filterData && this.feildOpt) {
					for (let i = 0; i < this.filterData.length; i++) {
						if (this.feildOpt[this.filterData[i].key]) {
							this.filterData[i].detailList = this.feildOpt[this.filterData[i].key];
						}
					}
				}
			},

			//筛选返回值
			resultConditon(obj) {
				this.$refs.condition.visibleDrawer = false;
				this.hasChoose = obj.hasChoose;
				console.log("===========obj", obj);
				this.searchParam.source = obj.result.source;
				this.searchParam.type = obj.result.type;
				this.searchParam.created_at = obj.result.created_at;
				this.onSearch();
			},
			orderbyChange(obj) {
				console.log("=======orderbyChange", 1);
				this.$refs.condition.visibleDrawer = true;
			},
			
			// 跳转到详情页
			goToDetail(item) {
				uni.navigateTo({
					url: `/pages/store/store?id=${item.id}&formData=${JSON.stringify(item)}`,
				});
			},
			
			deleteObj(item){
				this.$api.storeRemove(item.id).then(result => {
					// 失败进行的操作
					uni.showToast({
						title: "删除成功!",
						duration: 3000
					});
					this.onSearch();
					return;
				}).catch(res => {
					// 失败进行的操作
					uni.showToast({
						title: "删除失败!",
						duration: 3000
					});
					return;
				})
			},

			searchByName() {
				this.searchParam.name = this.name;
				this.onSearch();
			},
			async onSearch() {
				this.$api.storeList(this.searchParam).then(result => {
					this.datalist = result?result:[]
				}).catch(res => {
					// 失败进行的操作
					uni.showToast({
						title: "查询失败!",
						duration: 3000
					});
					return;
				})
			},
			
			delete(item){
				
			},
			
			handleFloatButtonClick() {
				uni.navigateTo({ url: '/pages/store/store' });
			},
		},
	};
</script>

<style lang="less" scoped>
	@import url("@/common/css/list_new.less");
</style>